package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.RecordBean;
import com.lwj.liwanjia.utils.CircleTransform;
import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018/1/11.
 */

public class TxRecordAdapter extends SuperBaseAdapter<RecordBean.DataBean> {

    private Context mContext;

    public TxRecordAdapter(Context context, List<RecordBean.DataBean> data) {
        super(context, data);

        this.mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder holder, RecordBean.DataBean item, int position) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = dateFormat.format(item.getTime());

        if (item.getType().equals("支付宝")) {
            Glide.with(mContext).load(item.getImage()).transform(new CircleTransform(mContext)).into((ImageView) holder.getView(R.id.iv_user));
            holder.setText(R.id.tv_user, item.getNick())
                    .setText(R.id.tv_state, item.getStatus())
                    .setText(R.id.tv_zhifubao_time, time)
                    .setText(R.id.tv_zhifubao_money, item.getMoney() + "")
                    .setText(R.id.tv_qudao, item.getType())
                    .setText(R.id.tv_zhifubao_name, item.getName())
                    .setText(R.id.tv_zhifubao_account, item.getAccount());
            if (item.getStatus().equals("转账异常")) {
                holder.setVisible(R.id.layout_unusual, true);
            } else {
                holder.setVisible(R.id.layout_unusual, false);
            }
        } else {
            Glide.with(mContext).load(item.getImage()).transform(new CircleTransform(mContext)).into((ImageView) holder.getView(R.id.iv_user1));
            holder.setText(R.id.tv_user1, item.getNick())
                    .setText(R.id.tv_state1, item.getStatus())
                    .setText(R.id.tv_yinhangka_time, time)
                    .setText(R.id.tv_yinhangka_money, item.getMoney() + "")
                    .setText(R.id.tv_qudao1, "银行卡")
                    .setText(R.id.tv_yinhang_name, item.getType())
                    .setText(R.id.tv_kaihu_name, item.getName())
                    .setText(R.id.tv_yinhangka_account, item.getAccount());
            if (item.getStatus().equals("转账异常")) {
                holder.setVisible(R.id.layout_unusual1, true);
            } else {
                holder.setVisible(R.id.layout_unusual1, false);
            }
        }
    }

    @Override
    protected int getItemViewLayoutId(int position, RecordBean.DataBean item) {
        if (item.getType().equals("支付宝")) {
            return R.layout.record_zhifubao_item;
        } else {
            return R.layout.record_yinhangka_item;
        }
    }
}
